import { request } from "../../utils/request.js";
import regeneratorRuntime from "../../utils/runtime.js";
var bsurl = require('../../utils/bsurl.js');
Page({
  data: {
    tabs:[
      {
        id:0,
        value:"热门",
        isActive:true
      },
      {
        id:1,
        value:"专辑",
        isActive:false
      },
      {
        id:2,
        value:"MV",
        isActive:false
      },
      {
        id:3,
        value:"歌手信息",
        isActive:false
      }
    ],
    songerId:0,
    songerCover:'',
    musicList:[],
    album:[],
    mv:[],
    songerdesc:{
      briefDesc:'',
      introduction:[]
    },
  },
  async getmusic(){
    let id=this.data.songerId;
    const songerMusic=await request({url:bsurl+'artists?id='+id});
    let musicList=songerMusic.hotSongs.map(v=>{
      return{
        name:v.name,
        author:v.ar[0].name,
        id:v.id,
        album:v.al.name,
      }
    })
    this.setData({
      songerCover:songerMusic.artist.img1v1Url,
      musicList
    }) 
  },
  //歌手专辑
  async getSongerAlbum(){
    let id=this.data.songerId;
    const albumInfo=await request({url: bsurl+'artist/album?limit=50&id='+id});
    let hotAlbums=albumInfo.hotAlbums.map(v=>{
      return{
        id:v.id,
        blurPicUrl:v.blurPicUrl,
        name:v.name,
        author:v.artist.name,
        alias:v.artist.alias[0]
      }
    })
    this.setData({
      album:hotAlbums
    })
  },
  //歌手mv
  async getSongerMv(){
    let id=this.data.songerId;
    const mvInfo=await request({url: bsurl+'artist/mv?id='+id});
    let mv=mvInfo.mvs.map(v=>{
      return{
        id:v.id,
        imgurl:v.imgurl,
        name:v.name,
        author:v.artistName,
        playCount:v.playCount
      }
    })
    this.setData({
      mv
    })
  },
  //歌手详情
  async getSongerInfo(){
    let id=this.data.songerId;
    const songerInfo=await request({url: bsurl+'artist/desc?id='+id});
    let {briefDesc,introduction}=songerInfo;
    let songerdesc={briefDesc,introduction};
    this.setData({
      songerdesc
    })
  },
  //切换事件
  handleTabsItemChange(e){
    const {index}=e.detail;
    let {tabs}=this.data;
    tabs.forEach((v,i) => i===index?v.isActive=true:v.isActive=false);
    this.setData({
    tabs
    })
    if(index==1){
      this.getSongerAlbum();
    }
    else if(index==2){
      this.getSongerMv();
    }
    else {
      this.getSongerInfo();
    }
  },
  onLoad: function (options) {
    let songerId=options.id;
    this.setData({
      songerId
    })
    this.getmusic();
  },
})